<template>
  <div class="chatgpt-view">
    <div class="chatgpt-view-title">
      <div class="chat-list-item-box">
        <div class="img">
          <ChatUser :imgUrl="ChatGPTItem.imgUrl"/>
        </div>
        <div class="detail-box">
          <div class="name">{{ChatGPTItem.name}}</div>
          <div class="detail">{{ChatGPTItem.detail}}</div>
        </div>
      </div>
    </div>
    <div class="chatgpt-view-chgatview">
      <div class="view-chgatview-box" >
        <div class="chat-view-list">
          <div class="chat-list-box" id="chat-scrollbar">
            <chat-view-list ref="child" @clearLoad="clearLoad" @scrollbarBT="scrollbarBT" />
          </div>
        </div>
        <div class="input-box">
          <div class="chat-box">
            <input class="chat-input" v-model="input" placeholder="请输入内容"/>
            <div class="btn" @click="sendMessageS">
              <img :class="rockrtClass" src="../../../../../assets/chat/rocket.png" />
            </div>
          </div>
          <div class="LoadAnimation" v-show="LoadShow">
            <div class="Load-box" :class="animationClass" >
              <div class="box-Load-icon">
                <i class="el-icon-loading"></i>
                <span>正在飞速加载ChatGPT的大脑🧠请耐心等待，不要随便点击🚫</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ChatUser from "@/components/chat/chat-user";
import ChatViewList from "@/components/chat/chat-view-list";
export default {
  name: "chatGPT-View",
  components: {ChatViewList, ChatUser},
  props:['ChatGPTItem'],
  data() {
    return {
      input: '',
      rockrtClass: "",
      animationClass: "",
      LoadShow: false,
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")): {},
    }
  },
  //计算属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    ChatGPTItem: function (val) {
      this.ChatGPTItem = val;
    }
  },
  //方法集合
  methods: {
    sendMessageS(){

      if(this.input!==""){
        this.rockrtClass = "zoomOutUp animated";
        let item = {
            userId: this.user.id,
            nickname: this.user.nickname,
            imgUrl:  this.user.avatarUrl,
            conversation: this.input,
            creationTime: new Date().toLocaleString()
        }
        this.animationClass = 'fadeInUp animated';
        this.LoadShow = true;
        this.$refs.child.sendMessage(item);
        this.input = "";
        setTimeout(()=>{
          this.rockrtClass = "zoomInUp animated";
        },2000)
      }else {
        this.$message('😫内容为空无法发送!');
      }

    },
    scrollbarBT(){
      var ele = document.getElementById("chat-scrollbar");
      setTimeout(()=>{
        //判断元素是否出现了滚动条
        if(ele.scrollHeight > ele.clientHeight) {
          //设置滚动条到最底部
          ele.scrollTop = ele.scrollHeight;

        }
      },1000)

    },
    clearLoad(){
      this.animationClass = '';
      this.LoadShow = false;
    }
  },
  //生命周期 一 创建完成(可以访问当前this实例)
  created() {
    console.log("当前时间",new Date().toLocaleString( ))
    console.log("当前页面"+this.ChatGPTItem.name)
  },
  //生命周期 一 挂载完成(可以访问DOM元素)
  mounted() {
    this.rockrtClass = "zoomInUp animated";
  },
  //生命周期 - 创建之前
  beforeCreate() {
  },
  //生命周期 - 挂载之前
  beforeMount() {
  },
  //生命周期 - 更新之前
  beforeUpdate() {
  },
  //生命周期 - 更新之后
  updated() {
  },
  //生命周期 - 销毁之前
  beforeDestroy() {
  },
  //生命周期 - 销毁完成
  destroyed() {
  },
  //如果页面有keep-alive缓存功能，这个函数会触发
  activated() {
  },
}
</script>

<style lang="less" scoped>
.chatgpt-view{
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .chatgpt-view-title{
    width: 100%;
    height: 120px;
    display: flex;
    align-items: center;
    .chat-list-item-box{
      width: 500px;
      height: 100px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .img{
        width: 80px;
        height: 80px;
        position: relative;
      }
      .detail-box{
        flex: 0.92;
        .name{
          font-size: 40px;
          font-weight: 700;
          color: white;
        }
        .detail{
          margin-top: 10px;
          font-size: 20px;
          color: #989ba2;
        }
      }
    }

  }
  .chatgpt-view-chgatview{
    flex: 0.98;
    display: flex;
    justify-content: center;
    align-items: center;
    .view-chgatview-box{
      width: 97%;
      height: 95%;
      background: #343647;
      border-radius: 25px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .chat-view-list{
        height: 65vh;
        display: flex;
        justify-content: center;
        align-items: center;
        .chat-list-box{
          width: 97%;
          height: 97%;
          padding: 0 10px;
          //overflow: hidden;
          overflow-y: auto;

          //box-sizing: border-box;
        }
      }
      .input-box{
        width: 100%;
        height: 100px;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
        .chat-box{
          width: 90%;
          height: 50px;
          display: flex;
          justify-content: space-between;
          .chat-input{
           flex: 0.95;
            height: 100% !important;
            border-radius: 15px;
            border: 2px solid #1d90f5;
            background: rgba(66, 69, 85,0.8);
            outline:none;
            color: white;
            font-size: 20px;
            padding: 0 15px !important;
          }
          input::-webkit-input-placeholder{
            color: width;
            padding-left: 10px;
            font-size:20px;

          }

          .btn{
            width: 100px;
            height: 50px;
            background: #1d90f5;
            border-radius: 15px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            img{
              width: 50px;
              height: 50px;
            }
          }

        }

        .LoadAnimation{
          position: absolute;
          width: 100%;
          top: -5px;
          display: flex;
          flex-direction: column;
          justify-content: flex-start;
          align-items: center;
          .Load-box{
            width: 100%;
            height: 80px;
            display: flex;
            border-radius: 40px 40px 0 0;
            background: linear-gradient(to bottom, rgba(29, 144, 245, 1), rgba(255, 255, 255, 0));
            justify-content: center;
            align-items: center;
            .box-Load-icon{
              width: 60%;
              height: 50%;
              color: white;
              display: flex;
              justify-content: center;
              align-items: center;
              span{
                margin-left: 10px;
              }
            }
          }
        }

      }
    }
  }
}


//动画
/*base code*/
.animated {
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}
.animated.infinite {
  -webkit-animation-iteration-count: infinite;
  animation-iteration-count: infinite;
}
.animated.hinge {
  -webkit-animation-duration: 2s;
  animation-duration: 2s;
}
/*the animation definition*/
@-webkit-keyframes zoomInUp {
  0% {
    opacity: 0;
    -webkit-transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
    transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
    -webkit-animation-timing-function: cubic-bezier(0.55, .055, .675, .19);
    animation-timing-function: cubic-bezier(0.55, .055, .675, .19)
  }
  60% {
    opacity: 1;
    -webkit-transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
    transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
    -webkit-animation-timing-function: cubic-bezier(0.175, .885, .32, 1);
    animation-timing-function: cubic-bezier(0.175, .885, .32, 1)
  }
}
@keyframes zoomInUp {
  0% {
    opacity: 0;
    -webkit-transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
    -ms-transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
    transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0);
    -webkit-animation-timing-function: cubic-bezier(0.55, .055, .675, .19);
    animation-timing-function: cubic-bezier(0.55, .055, .675, .19)
  }
  60% {
    opacity: 1;
    -webkit-transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
    -ms-transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
    transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0);
    -webkit-animation-timing-function: cubic-bezier(0.175, .885, .32, 1);
    animation-timing-function: cubic-bezier(0.175, .885, .32, 1)
  }
}
.zoomInUp {
  -webkit-animation-name: zoomInUp;
  animation-name: zoomInUp
}


/*base code*/
.animated {
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}
.animated.infinite {
  -webkit-animation-iteration-count: infinite;
  animation-iteration-count: infinite;
}
.animated.hinge {
  -webkit-animation-duration: 2s;
  animation-duration: 2s;
}
/*the animation definition*/
@-webkit-keyframes zoomOutUp {
  40% {
    opacity: 1;
    -webkit-transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
    transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
    -webkit-animation-timing-function: cubic-bezier(0.55, .055, .675, .19);
    animation-timing-function: cubic-bezier(0.55, .055, .675, .19)
  }
  100% {
    opacity: 0;
    -webkit-transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
    transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
    -webkit-transform-origin: center bottom;
    transform-origin: center bottom;
    -webkit-animation-timing-function: cubic-bezier(0.175, .885, .32, 1);
    animation-timing-function: cubic-bezier(0.175, .885, .32, 1)
  }
}
@keyframes zoomOutUp {
  40% {
    opacity: 1;
    -webkit-transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
    -ms-transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
    transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0);
    -webkit-animation-timing-function: cubic-bezier(0.55, .055, .675, .19);
    animation-timing-function: cubic-bezier(0.55, .055, .675, .19)
  }
  100% {
    opacity: 0;
    -webkit-transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
    -ms-transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
    transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0);
    -webkit-transform-origin: center bottom;
    -ms-transform-origin: center bottom;
    transform-origin: center bottom;
    -webkit-animation-timing-function: cubic-bezier(0.175, .885, .32, 1);
    animation-timing-function: cubic-bezier(0.175, .885, .32, 1)
  }
}
.zoomOutUp {
  -webkit-animation-name: zoomOutUp;
  animation-name: zoomOutUp
}



</style>